package keni.html.android.framework.connectionChannel;

import java.util.Stack;

public abstract class ChannelBase implements IChannel {
	
	Stack<IChannelSink> channelSinks=new Stack<IChannelSink>();
	
	public void pushNewChannelSink(IChannelSink channelSink)
	{
		if(!channelSinks.isEmpty()){
			IChannelSink next=channelSinks.peek();
			channelSink.setNextChannelSink(next);
			next.setPreviousChannelSink(channelSink);
		}

		channelSinks.push(channelSink);
	}
	
	public void doRequest(RequestMessage message,Header header)
	{
		if(!channelSinks.isEmpty())
		{
			IChannelSink sink=channelSinks.peek();
			sink.processRequest(message, header);
		}
	}
	
	 public  ResponseMessage getResponseMessage(){
		 if(!channelSinks.isEmpty())
			{
				IChannelSink sink=channelSinks.peek();
				return sink.getResponseMessage();
			}
		 return null;
	   }
	   public  Header getResponseHeader()
	   {
		   if(!channelSinks.isEmpty())
			{
				IChannelSink sink=channelSinks.peek();
				return sink.getResponseHeader();
			}
		   return null;
	   }

}
